package com.eventx.service.def;

import com.eventx.bus.event.EventHandlerData;
import com.eventx.bus.event.EventSubscriber;
import com.eventx.bus.message.MessageData;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

import java.util.EventListener;

/**
 * @author: anrror
 **/
public class DefaultEventListenner implements EventListener {

    private EventSubscriber eventSubscriber;

    public DefaultEventListenner(EventSubscriber eventSubscriber) {
        this.eventSubscriber = eventSubscriber;
    }


    public void onEvent(String eventName,MessageData obj){
        if(eventName.equals(eventSubscriber.getEventHandler().getEventName())){
            try {
                eventSubscriber.getEventHandler().handler((EventHandlerData)obj.getData());
            } catch (Exception e) {
            }
        }
    }


}
